package cn.stylefeng.guns.modular.shuheng.service;

import cn.stylefeng.guns.core.common.node.ZTreeNode;
import cn.stylefeng.guns.core.shiro.ShiroUser;
import cn.stylefeng.guns.modular.shuheng.entity.Level;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.stylefeng.guns.modular.shuheng.mapper.LevelMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import cn.stylefeng.guns.core.common.page.LayuiPageFactory;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author zhengpp
 * @since 2021-03-07
 */
@Service
public class LevelService extends ServiceImpl<LevelMapper,Level> {
    public Page<Map<String,Object>> listLevel(String levelName,String  year) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.selectLevel(page,levelName,year);
    }

    public void deleteByYear(Integer year) {
        QueryWrapper<Level> wrapper = new QueryWrapper<>();
        wrapper.eq("year",year);
        this.baseMapper.delete(wrapper);
    }

    public List<ZTreeNode> tree(Integer year,Integer regionType) {
        return this.baseMapper.tree(year,regionType);
    }

    public List<Integer> listYears() {
        return this.baseMapper.listYears();
    }

    /**
     * 当前level下是否存在当前月之前未完成的任务
     * @param nowYear
     * @param nowMonth
     * @param levelId
     * @param user
     * @return
     */
    public boolean exitNotDeal(Integer nowYear, Integer nowMonth, Long levelId, ShiroUser user) {

        List<Map<String,Object>> list = this.baseMapper.listNotDeal(nowYear,nowMonth,levelId,user.getUserLevel(),user.getCity(),user.getCounty());
        if(list!=null && list.size()>0){
            return true;
        }
        return false;
    }
}
